package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.console.excel.ExportExcel;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.pubdef.dto.register.RegisterGotoVoiceRoomCfgDTO;
import com.qumitech.visualnovel.service.account.RegisterService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: RegisterController
 * @description:
 * @author: bzhao
 * @date: 2020/11/9 4:48 下午
 * copyright(c) 2017-2020 趣米（武汉）科技有限公司
 */
@RestController
@RequestMapping("/api/register")
public class RegisterController {

    @Autowired
    RegisterService registerService;

    @GetMapping("/goto/voice_room")
    public BaseRsp listRegisterGotoVoiceRoomCfg(@RequestParam(name = "limit", required = false, defaultValue = "10") String limit,
                                     @RequestParam(name = "offset", required = false, defaultValue = "0") String offset,
                                     @RequestParam(name = "sub_channel", required = false) String subChannel){
        Map<String, String> paramMap = new HashMap<>(16);
        paramMap.put("limit", limit);
        paramMap.put("offset", offset);

        if(StringUtils.isNotEmpty(subChannel)){
            paramMap.put("sub_channel", subChannel);
        }
        return registerService.listRegisterGotoVoiceRoomCfg(paramMap);
    }

    @PutMapping("/goto/voice_room")
    public BaseRsp saveRegisterGotoVoiceRoomCfg(@RequestBody RegisterGotoVoiceRoomCfgDTO dto){
        return registerService.saveRegisterGotoVoiceRoomCfg(dto);
    }

    @PostMapping("/goto/voice_room")
    public BaseRsp updateRegisterGotoVoiceRoomCfg(@RequestBody RegisterGotoVoiceRoomCfgDTO dto){
        return registerService.updateRegisterGotoVoiceRoomCfg(dto);
    }



    @DeleteMapping("/goto/voice_room/{id}")
    public BaseRsp deleteRegisterGotoVoiceRoomCfg(@PathVariable("id") Long id){
        return registerService.deleteRegisterGotoVoiceRoomCfg(id);
    }

    @GetMapping("/virtual_account")
    public BaseRsp listVirtualAccounts(@RequestParam(name = "channel", required = false) String channel,
                                      @RequestParam(name = "startTime", required = false) String startTime,
                                      @RequestParam(name = "endTime", required = false) String endTime,
                                      @RequestParam(name = "limit", required = false, defaultValue = "10") int limit,
                                      @RequestParam(name = "offset", required = false, defaultValue = "0") int offset
                                      ) {
        return registerService.listVirtualAccounts(channel, startTime, endTime, limit, offset);
    }

    @GetMapping("/virtual_account/detail")
    @ExportExcel(itemKeys = {"accountId","userName","level","coin","diamond","recharge","consume","phoneNum","signature", "registerTime", "lastActiveTime", "realName", "idCard"},
            itemNames = {"ID","昵称","等级","嗨币","钻石","充值金额","总收益","手机号","签名", "注册时间", "上次活跃时间", "姓名", "身份证号"},
            listKey = "data")
    public BaseRsp listVirtualAccountsDetail(@RequestParam(value = "limit", required = false, defaultValue = "20") Integer pageSize,
                                             @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
                                             @RequestParam(name = "channel") String channel,
                                             @RequestParam(name = "targetDate") String targetDate) {
        return registerService.listVirtualAccountsDetail(channel, targetDate, pageSize, offset);
    }

}
